﻿using System;
using System.Data.Linq;

namespace DatabaseStorageDemo.Model
{
   public class FileStorageDataContext : DataContext
   {
      public FileStorageDataContext( string connectionString )
         : base( connectionString )
      {

      }

      /// <summary>
      /// Gets the files table.
      /// </summary>
      /// <value>The files table.</value>
      public Table<DatabaseFile> Files
      {
         get
         {
            return GetTable<DatabaseFile>();
         }
      }

      /// <summary>
      /// Saves the specified new file.
      /// </summary>
      /// <param name="newFile">The new file.</param>
      public void Save( DatabaseFile newFile )
      {
         if ( null == newFile )
            throw new ArgumentNullException( "newFile" );

         Files.InsertOnSubmit( newFile );
         SubmitChanges();
      }
   }
}
